****APPENDIX FIGURE D1-D2****

cd "$main_dir/output/figures/appendix_d"

graph set window fontface "Palatino"

global basic 	sex marital religion edu ethnicity birth_state
global extra	employment_status occupation income urban
global time 	survey_year age generation
global polit    party partisan

//--------------------------------------------------------
//Define relevant program
//--------------------------------------------------------

capture program drop standardize
program define standardize
	
	args depvar
	
	cap drop z*
	local varlist `depvar' wgrowth_rate_1 yob_ln_gdppc
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant data
//--------------------------------------------------------

clear
use "$data_dir/clean/anes_final.dta"

//--------------------------------------------------------
//Create Figure D1
//--------------------------------------------------------

matrix coef1 = J(21, 3, .)
	matrix coln coef1 = coefficients lcl ucl
	matrix rown coef1 = "1958" "1964" "1966" "1968" "1970" "1972" ///
						"1974" "1976" "1978" "1980" "1982" "1984" ///
						"1986" "1988" "1990" "1992" "1994" "1996" ///
						"2000" "2008"

local i = 1
foreach x in ///
	1958 1964 1966 1968 1970 1972 ///
	1974 1976 1978 1980 1982 1984 ///
	1986 1988 1990 1992 1994 1996 ///
	2000 2008 ///
	{
		qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc if survey_year!=`x', absorb(state_code $time $basic $extra $polit) cluster(yob) level(95)
		standardize trust_fed_govt
		qui reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc if survey_year!=`x', absorb(state_code $time $basic $extra $polit) cluster(yob) level(95)
		
		mat os = r(table)
		mat coef1[`i',1] = os[1,1]
		mat coef1[`i',2] = os[5,1]
		mat coef1[`i',3] = os[6,1]
		
		di "Regression for `x' dropped complete"
		local ++i
	}

qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob) level(95)
standardize trust_fed_govt
qui reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob) level(95)
scalar beta = _b[zwgrowth_rate_1]
coefplot (matrix(coef1[,1]), ci((coef1[,2] coef1[,3]))), ///
	graphregion(color(white)) bgcolor(white) xline(0, lcolor(maroon)) xlabel(,labs(vsmall)) ylabel(,labs(vsmall)) xline(`=beta', lpattern(dash) lcolor(maroon)) ///
	ytitle("Survey Year Dropped",size(small) margin(small)) xtitle("Effect Size", size(small))
	graph export "figure_d1.png", replace
	
//--------------------------------------------------------
//Create Figure D2
//--------------------------------------------------------

matrix coef1 = J(48, 3, .)
	matrix coln coef1 = coefficients lcl ucl
	matrix rown coef1 = "AL" "AR" "AZ" "CA" "CO" "CT" "DC" "DE" "FL" "GA" "IA" ///
						"ID" "IL" "IN" "KS" "KY" "LA" "MA" "MD" "ME" "MI" "MN" ///
						"MO" "MS" "MT" "NC" "ND" "NE" "NH" "NJ" "NM" "NV" "NY" ///
						"OH" "OK" "OR" "PA" "RI" "SC" "SD" "TN" "TX" "UT" "VA" ///
						"WA" "WI" "WV" "WY"

local i = 1
foreach x in ///
	AL AR AZ CA CO CT DC DE FL GA IA ///
	ID IL IN KS KY LA MA MD ME MI MN ///
	MO MS MT NC ND NE NH NJ NM NV NY ///
	OH OK OR PA RI SC SD TN TX UT VA ///
	WA WI WV WY ///
	{
		qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc if state_code!="`x'", absorb(state_code $time $basic $extra $polit) cluster(yob) level(95)
		standardize trust_fed_govt
		qui reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc if state_code!="`x'", absorb(state_code $time $basic $extra $polit) cluster(yob) level(95)
		
		mat os = r(table)
		mat coef1[`i',1] = os[1,1]
		mat coef1[`i',2] = os[5,1]
		mat coef1[`i',3] = os[6,1]
		
		di "Regression for `x' dropped complete"
		local ++i
	}

qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob) level(95)
standardize trust_fed_govt
qui reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob) level(95)
scalar beta = _b[zwgrowth_rate_1]
coefplot (matrix(coef1[,1]), ci((coef1[,2] coef1[,3]))), ///
	graphregion(color(white)) bgcolor(white) xline(0, lcolor(maroon)) xlabel(,labs(vsmall)) ylabel(,labs(vsmall)) xline(`=beta', lpattern(dash) lcolor(maroon)) ///
	ytitle("State Dropped",size(small) margin(small)) xtitle("Effect Size", size(small))
	graph export "figure_d2.png", replace
	
